new Vue({
    el: '#intro',
    mounted() {
        this.createQrCode()
    },
    data() {
        return {
        }
    },
    computed: {
        redirectUri() {
            let protocol = window.location.protocol
            let host = window.location.host
            return protocol + '//' + host + '/qrcode/qywx-login-redirect'
        }
    },
    methods: {
        createQrCode() {
            localStorage.setItem('corpId', 'wwdd2c810bc4c851f4');
            localStorage.setItem('agentId', '1000002');
            localStorage.setItem('wwLoginUrl', 'https://wwcdn.weixin.qq.com/node/wework/wwopen/js/wwLogin-1.2.5.js');
            // ----------
            let corpId =localStorage.getItem('corpId')
            if (!corpId) {
                // if navigate /#/qywx-login directly, need get corpId agentid from server
                let protocol = window.location.protocol
                let host = window.location.host
                window.location.href = protocol + '//' + host
                return
            }
            const s = document.createElement('script')
            s.type = 'text/javascript'
            s.src = localStorage.getItem('wwLoginUrl')
            const wxElement = document.body.appendChild(s)
            let _this = this
            wxElement.onload = function() {
                new window.WwLogin({
                    "id": 'qrCode',
                    "appid": localStorage.getItem('corpId'),
                    "agentid": localStorage.getItem('agentId'),
                    "redirect_uri": encodeURIComponent(_this.redirectUri),
                })
            }
        },
    },
});
